package my.diplom.web.servlet;

import my.diplom.dao.service.ApplicationService;
import my.diplom.entity.Application;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;

import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.context.WebApplicationContext;

/**
 * Created by IntelliJ IDEA.
 * User: gb
 * Date: 13.09.2009
 * Time: 1:26:01
 * To change this template use File | Settings | File Templates.
 */
public class AjaxServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if (request.getParameter("appId") != null && !request.getParameter("appId").equals("")) {
            WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
               ApplicationService applicationService =(ApplicationService)springContext.getBean("applicationService");


            Long applicationId = Long.parseLong(request.getParameter("appId"));
            try {
                Application application = applicationService.getById(applicationId);
                request.setAttribute("application", application);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
